package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.impl.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    @GetMapping("/send")
    public AjaxResult sendSms(String mobile) throws Exception {
        String s = smsService.sendSms(mobile);
        return AjaxResult.success(s);
    }

    @GetMapping("/validateCode")
    public AjaxResult validateCode(String mobile, String code) throws Exception {
        Boolean b = smsService.checkKaptcha(mobile, code);
        if(b){
            return AjaxResult.success();
        }else{
            return AjaxResult.warn("验证码失效");
        }

    }
}
